using MicroMsg.Plugin.Sns.Scene;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace MicroMsg.UI.Page
{
	public class MasterPageSlideView : BasePage
	{
		private const string TAG = "MasterPageSlideView";
		private List<TimeLineObject> tloList = new List<TimeLineObject>();
		private int nowIndex;
		private AlbumSlideImage[] albumImage = new AlbumSlideImage[3];
		private bool bIsFirstLoad = true;
		private ApplicationBar mBar;
		private ApplicationBarIconButton PreviousIcon;
		private ApplicationBarIconButton OKIcon;
		private ApplicationBarIconButton NextIcon;
		internal Grid LayoutRoot;
		internal Canvas ImagePanel;
		internal PanoramaSlideCtrl mPanoramaSlideCtrl;
		private bool _contentLoaded;
		public MasterPageSlideView()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.MasterPageSlideView_Loaded));
		}
		private void MasterPageSlideView_Loaded(object sender, RoutedEventArgs e)
		{
			if (this.bIsFirstLoad)
			{
				base.set_ApplicationBar(this.GetAppBar());
				this.RefreshUI();
				this.bIsFirstLoad = false;
			}
		}
		protected override void OnPageIn(object[] object_0)
		{
			if (object_0 != null && Enumerable.Count<object>(object_0) == 2)
			{
				this.tloList = (object_0[0] as List<TimeLineObject>);
				this.nowIndex = (int)object_0[1];
				this.InitSlideImage();
			}
		}
		private void InitSlideImage()
		{
			this.mPanoramaSlideCtrl.nowIndex = 0;
			this.mPanoramaSlideCtrl.nowMIndex = this.nowIndex;
			this.mPanoramaSlideCtrl.tloList = this.tloList;
			this.mPanoramaSlideCtrl.InitData();
			this.mPanoramaSlideCtrl.SlideToNextSnsInfo += new PanoramaSlideCtrl.SlideToNextSnsInfoEvent(this.mPanoramaSlideCtrl_SlideToNextSnsInfo);
			this.RefreshUI();
		}
		private void mPanoramaSlideCtrl_SlideToNextSnsInfo(object sender, object object_0)
		{
			this.RefreshUI();
		}
		private void RefreshUI()
		{
			if (this.PreviousIcon == null || this.NextIcon == null)
			{
				return;
			}
			if (this.mPanoramaSlideCtrl.nowMIndex == 0)
			{
				this.PreviousIcon.set_IsEnabled(false);
			}
			else
			{
				this.PreviousIcon.set_IsEnabled(true);
			}
			if (this.mPanoramaSlideCtrl.nowMIndex == this.tloList.get_Item(0).content.mediaList.get_Count() - 1)
			{
				this.NextIcon.set_IsEnabled(false);
				return;
			}
			this.NextIcon.set_IsEnabled(true);
		}
		private ApplicationBar GetAppBar()
		{
			this.mBar = new ApplicationBar();
			this.mBar.set_IsMenuEnabled(true);
			this.mBar.set_IsVisible(true);
			if (this.mBar != null)
			{
				this.mBar.set_BackgroundColor(((SolidColorBrush)R.theme.COMMON_APPBAR_BK_BRUSH).get_Color());
				this.mBar.set_ForegroundColor(((SolidColorBrush)R.theme.COMMON_APPBAR_FG_BRUSH).get_Color());
			}
			this.PreviousIcon = new ApplicationBarIconButton(new Uri("/Source/Plugin/Sns/Common/Resource/ico_prev.png", 2));
			this.PreviousIcon.set_Text(strings.Album_SlideView_Previous);
			this.PreviousIcon.add_Click(new EventHandler(this.PreviousIcon_Click));
			this.mBar.get_Buttons().Add(this.PreviousIcon);
			this.OKIcon = new ApplicationBarIconButton(new Uri("/icons/appbar.check.rest.png", 2));
			this.OKIcon.set_Text(strings.COM_Confirm);
			this.OKIcon.add_Click(new EventHandler(this.OKIcon_Click));
			this.mBar.get_Buttons().Add(this.OKIcon);
			this.NextIcon = new ApplicationBarIconButton(new Uri("/Source/Plugin/Sns/Common/Resource/ico_next.png", 2));
			this.NextIcon.set_Text(strings.Album_SlideView_Next);
			this.NextIcon.add_Click(new EventHandler(this.NextIcon_Click));
			this.mBar.get_Buttons().Add(this.NextIcon);
			return this.mBar;
		}
		private void PreviousIcon_Click(object sender, EventArgs e)
		{
			this.mPanoramaSlideCtrl.GoPrevious();
		}
		private void NextIcon_Click(object sender, EventArgs e)
		{
			this.mPanoramaSlideCtrl.GoNext();
		}
		private void OKIcon_Click(object sender, EventArgs e)
		{
			List<TloMedia> list = new List<TloMedia>();
			TloMedia tloMedia = this.tloList.get_Item(0).content.mediaList.get_Item(this.mPanoramaSlideCtrl.nowMIndex);
			list.Add(tloMedia);
			SnsPostService.UploadAndPost(list, null, null, null, 0u, 0, SnsObjectType.MMSNS_OBJECT_BACKGROUND, BgImgType.MMSNS_SETBGIMG_MASTERPIC, null);
			PageManager.getInstance().PopPage();
			PageManager.getInstance().PopPage();
			base.GoBack();
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Sns/Common/UI/AlbumCover/MasterPageSlideView.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.ImagePanel = (Canvas)base.FindName("ImagePanel");
			this.mPanoramaSlideCtrl = (PanoramaSlideCtrl)base.FindName("mPanoramaSlideCtrl");
		}
	}
}
